$(function () {

    $("#sendMessageNotice .btn-save").click(function () {

        var messageNoticeTitle =$('#sendMessageNoticeTitle option:selected').val().trim();
        if(messageNoticeTitle === null || messageNoticeTitle === ""){
            $MB.n_danger("请选择添加标题！");
            $('#sendMessageNotice').modal('hide')
            return;
        }
        var messageNoticeValue = $("#sendMessageNoticeValue").val();
        if(messageNoticeValue === null || messageNoticeValue === ""){
            $MB.n_danger("请填写添加内容！");
            $('#sendMessageNotice').modal('hide')
            return;
        }

        var phone = $("#phone").val();
        if(phone === null || phone === ""){
            $MB.n_danger("请填写添加模板号！");
            $('#sendMessageNotice').modal('hide')
            return;
        }
        var name = $("#sendName").val();
        if(name === null || name === ""){
            $MB.n_danger("请填写操作人！");
            $('#sendMessageNotice').modal('hide')
            return;
        }


        var remakes = $("#remakes").val();

        var par = new Object()
        par.messageNoticeValue = messageNoticeValue;
        par.messageNoticeTitle = messageNoticeTitle;
        par.phone = phone;
        par.remakes = remakes;
        par.name = name;

        $.post(ctx+"messageNotice/sendMessageNotice",par,function (r) {
            if (r.code !== 0) {
                $MB.n_danger(r.msg);
                $('#card-read').modal('hide')
                return;
            }else{
                $MB.n_success("短信已发送！");
                // print(r);
                $('#card-read').modal('hide')
                console.log(r)
                return;
            }
        });
    });
    $("#sendMessageNotice .btn-save").click(function () {
        closeModal();
    });
    $("#sendMessageNotice .btn-close").click(function () {
        closeModal();
    });
    function closeModal() {
        $MB.closeAndRestModal("sendMessageNotice");
        clearInfo();
    }
});




//标题下拉选
function messageNoticeValue() {
    $("#sendMessageNoticeTitle").empty();
    $.ajax({
            type:"get",
            dataType:"json",
            contentType:"application/json;charset=utf-8",
            url:ctx+"messageNotice/sendMessageNoticeTitle",

            success:function(result){

                $("#sendMessageNoticeTitle").append("<option value=\"\" selected=\"selected\" disabled=\"disabled\"  style='display: none'></option>");
                $.each(result,function(index,value){

                    $("#sendMessageNoticeTitle").append("<option value='"+value.id+"'>"+value.messageNoticeTitle+"</option>");

                })
            },
            error : function(XMLHttpRequest, textStatus, errorThrown) {
                alert(errorThrown);
            },
            async:false             //false表示同步
        }

    );
}
//内容下拉选
$(function () {

    $("#sendMessageNoticeTitle").click(function () {
        var obj = new Object();
        obj.id = $('#sendMessageNoticeTitle option:selected').val().trim();
        $.post(ctx+"messageNotice/sendMessageValue",obj,function(result){
            $("#sendMessageNoticeValue").val(result.messageNoticeValue);
        });
    });
});